local heming_slash = fk.CreateSkill {
  name = "3s__heming_slash",
  tags = { "Turn" },
}

Fk:loadTranslationTable{
  ["3s__heming_slash"] = "合鸣[杀]",
  [":3s__heming_slash"] = "每回合限一次，你可视为使用无次数限制的【杀】，然后令目标角色将手牌数调整至其体力值。",
}


heming_slash:addEffect("viewas", {
  pattern = "slash",
  prompt = "#3s__heming-slash",
  card_filter = Util.FalseFunc,
  view_as = function(self, player, cards)
    if #cards ~= 0 then return end
    local slash = Fk:cloneCard("lvshi__slash")
    slash.skillName = "3s__heming"
    return slash
  end,
  enabled_at_play = function(self, player)
    return player:getMark("heming-slash-turn") == 0
  end,
  enabled_at_response = function(self, player, response)
    return player:getMark("heming-slash-turn") == 0 and not response
  end,
  before_use = function(self, player, use)
    player:addCardUseHistory("slash", -1)
    player.room:addPlayerMark(player, "heming-slash-turn")
  end,
  after_use = function(self, player, use)
    local room = player.room
      for _, p in ipairs(use.tos) do
        -- 令目标角色将手牌数调整至其体力值
        if p:getHandcardNum() ~= p.hp then
            local n = math.abs(p:getHandcardNum() - p.hp)
            if p:getHandcardNum() > p.hp then
             room:askToDiscard(p, {
              skill_name = "3s__heming",
              cancelable = false,
              min_num = n,
              max_num = n,
              include_equip = false,
             })
            else
              p:drawCards(n, "3s__heming")
            end
        end
    end
  end,
})

heming_slash:addEffect("targetmod", {
  bypass_times = function(self, player, skill, scope, card)
    if player:hasSkill(heming_slash.name) and card and card.skillName == "3s__heming" and scope == Player.HistoryPhase then
      return true
    end
  end,
})

return heming_slash
